package hn.cch.spring_boot_cloud_consul.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RequestMapping(value = "consul")
@RestController
public class ConsulController {

    @Autowired
    private LoadBalancerClient loadBalancer;
    @Autowired
    private DiscoveryClient discoveryClient;


    @GetMapping(value = "services")
    public Object services() {

        return discoveryClient.getInstances("spring-consul");
    }
    @GetMapping(value = "discover")
    public Object discover() {

        return loadBalancer.choose("spring-consul").getUri().toString();
    }
}
